<template>
	<view class="app_main">
		<NavTabbar activeTab="user"></NavTabbar>
		<view class="navbar">
			<view class="fixed">
				<!-- 状态栏 时间 电量 信号 -->
				<view :style="{height: navbarStatusHeight+'px'}"></view>
				<!-- #ifdef H5 || APP-PLUS || MP-ALIPAY -->
				<view class="navbar-content">
					<view class="navBar">
						<view>{{store.state.userInfo.customer}}</view>
					</view>
				</view>
				<!-- #endif -->
				<!-- #ifndef H5 || APP-PLUS || MP-ALIPAY -->
				<!-- 胶囊按钮左侧位置 -->
				<view class="navbar-content" :style="{width:'100%',height:navBarHeight+'px'}">
					<view class="navBar">
						<view>{{store.state.userInfo.customer}}</view>
					</view>
				</view>
				<!-- #endif -->
			</view>
			<!-- 设置占位 将微信小程序的状态栏高度预留出来 -->
			<!-- <view :style="{height:navbarStatusHeight+navBarHeight+'px' }"></view> -->
		</view>
		<view class="conten_block">
			<view class="logo_top">
				<view class="img">
					<image mode="aspectFill" class="user_img" v-if="store.state.userInfo.avatar"
						:src="store.state.userInfo.avatar" @click="lookPic(store.state.userInfo.avatar)" />
					<uni-icons size="100" color="#007cff" type="contact" v-else></uni-icons>
				</view>
				<view class="user_inf">
					<view class="user_name">
						<view class="name">
							{{store.state.userInfo.name}}
						</view>
						<view class="edit" @click="goEdit">
							<uni-icons type="compose" color="#007cff" size="14"></uni-icons> 编辑
						</view>
					</view>
					<view class="phone_tip">
						{{store.state.userInfo.phone}}
					</view>
				</view>
			</view>
			<uni-list :border="false">
				<uni-list-item title="绑定手机" showArrow thumb="/static/network/user/phone.svg" @click="goAcl" link
					thumb-size="sm" :rightText="store.getters.setProcessingTel" />
				<!-- <uni-list-item title="切换角色" :rightText="store.state.userInfo.network" showArrow @click="changeRole" link
					thumb="/static/network/user/role.svg" thumb-size="sm" /> -->
				<!-- 先隐藏 -->
				<!-- 	<uni-list-item title="创建服务商" showArrow @click="createNetwork" clickable
					thumb="/static/network/user/net_ing.svg" thumb-size="sm" />
				<uni-list-item title="加入服务商" showArrow @click="addNetwork" clickable
					thumb="/static/network/user/add_net.svg" thumb-size="sm" /> -->
				<uni-list-item title="修改密码" showArrow @click="gochangePwd" link
					thumb="/static/network/user/change_pwd.svg" thumb-size="sm" />
				<uni-list-item title="我的地址" showArrow @click="bmcAddress" link thumb="/static/network/user/address.svg"
					thumb-size="sm" />
				<uni-list-item title="退出登录" showArrow @click="onLogout" link thumb="/static/network/user/icon_exit.svg"
					thumb-size="sm" />
			</uni-list>
		</view>
		<!-- 退出登录弹窗 -->
		<uni-popup ref="logoutDialog" type="dialog">
			<uni-popup-dialog cancelText="否" confirmText="是" title="通知" content="是否退出登录?" @confirm="dialogConfirm"
				@close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted } from "vue";
	import store from '@/store_network/index.js'
	import { onLoad } from '@dcloudio/uni-app'
	import apiLogin from '@/util/network_api/login.js'
	import NavTabbar from "@/components/u-network/nav-tabbar.vue"
	onLoad(async () => {
		//显示加载框
		uni.showLoading({
			title: '加载中',
		});
		// 获取用户信息
		await store.dispatch('getUpdataUser')
		// //隐藏加载框
		uni.hideLoading();
	})
	const logoutDialog = ref()
	const navbarStatusHeight = ref(0)
	const navBarHeight = ref(0)
	const navBarWidth = ref(375)
	onMounted(() => {
		const info = uni.getSystemInfoSync()
		navbarStatusHeight.value = info.statusBarHeight
		// 根据微信小程序的右上侧的胶囊样式 设置导航栏内容的高度
		// 条件编译 以下三个不支持胶囊样式
		// #ifndef H5 || APP-PLUS || MP-ALIPAY
		const menuInfo = uni.getMenuButtonBoundingClientRect()
		// 导航栏内容的高度 = (胶囊底部的高度 - 状态栏的高度) + (胶囊顶部的高度 - 状态栏的高度)
		navBarHeight.value = (menuInfo.bottom - info.statusBarHeight) + (menuInfo.top - info.statusBarHeight)
		// 导航栏内容的宽度  除开胶囊按钮左侧的内容宽度
		navBarWidth.value = menuInfo.left
		// #endif
	})
	// 预览图片
	const lookPic = (list) => {
		uni.previewImage({
			urls: [list]
		})
	}
	//退出
	const onLogout = () => {
		logoutDialog.value.open()
	}
	// 关闭弹窗
	const dialogClose = () => {
		logoutDialog.value.close()
	}
	// 确认退出登录
	const dialogConfirm = () => {

		uni.reLaunch({
			url: "/pages/pages_network/login/login"
		})
		apiLogin.logout().then(res => {
			uni.removeStorageSync('access-network')
			if (res.code == 20000) {
			}
		})
	}
	// 绑定手机
	const goAcl = () => {
		uni.navigateTo({
			url: "/pages_network/user/acl"
		})
	}
	// 修改密码
	const gochangePwd = () => {
		uni.navigateTo({
			url: "/pages_network/user/pwd"
		})
	}
	// 编辑信息
	const goEdit = () => {
		uni.navigateTo({
			url: "/pages_network/user/edit"
		})
	}
	// 地址库
	const bmcAddress = () => {
		uni.navigateTo({
			url: "/pages_network/user/address"
		})
	}
	// 切换角色
	const changeRole = () => {
		uni.navigateTo({
			url: "/pages_network/login/role?isBack=false"
		})
	}
	// 加入服务商
	const addNetwork = () => {
		uni.navigateTo({
			url: "/pages_network/user/add_network"
		})
	}
	// 创建服务商
	const createNetwork = () => {
		uni.navigateTo({
			url: "/pages_network/user/create_network"
		})
	}
</script>

<style lang="scss" scoped>
	.navbar {
		.fixed {
			// position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100%;

			.navbar-content {
				position: relative;
				display: flex;
				align-items: center;
				width: 100%;
				height: 80rpx;

				.navBar {
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;
					position: absolute;
					top: 0;
					bottom: 0;
					width: 100%;
					height: 100%;
					font-size: 32rpx;
					font-weight: bold;
					color: #fff;
				}
			}
		}
	}

	.logo_top {
		display: flex;
		padding: 20rpx 30rpx 30rpx;

		.img {
			width: 110rpx;
			height: 110rpx;
			border-radius: 50%;
			margin-right: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			overflow: hidden;
			background-color: #fff;

			.user_img {
				width: 110rpx;
				height: 110rpx;
			}
		}

		.user_inf {
			display: flex;
			flex-direction: column;
			justify-content: center;

			.user_name {
				display: flex;
				align-items: center;

				.name {
					color: #fff;
					font-size: 32rpx;
					margin-right: 14rpx;
				}

				.edit {
					display: flex;
					font-size: 20rpx;
					color: #007cff;
					border-radius: 4rpx;
					background: #f2f9ff;
					padding: 6rpx 10rpx;
					text-align: center;
				}
			}

			.phone_tip {
				margin-top: 10rpx;
				// color: rgba(85, 85, 85, 1);
				color: #fff;
				font-size: 24rpx;

			}
		}
	}

	.app_main {
		width: 100%;
		height: 100vh;
		// background-image: url('@/static/network/login/bg_login.png');
		background: linear-gradient(#007cff 10%, #fafafa 30%);
		background-repeat: no-repeat;
		background-size: cover;
		background-position: top;
		position: relative;

		.conten_block {
			// position: absolute;
			// margin-top: 12%;
			width: 100%;

			:deep(.uni-list) {
				// background-color: transparent !important;
				border-radius: 30rpx 30rpx 0 0;
				padding: 14rpx;

				.uni-list-item__content-title {
					font-size: 30rpx;
				}

				.uni-list-item__extra-text {
					font-size: 28rpx;
				}

				.uni-list-item {
					padding: 11rpx 0;
					background-color: transparent !important;
				}
			}
		}
	}
</style>